package com.example.a79273.shandianban.adapter;

import android.content.Context;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewParent;
import android.widget.ImageView;

import java.util.List;

/**
 * Created by Administrator on 2016/8/29.
 */
public class StyleVpAdapter extends PagerAdapter{
private List<ImageView>mData;

    public StyleVpAdapter(List<ImageView> mData) {
        this.mData = mData;
    }

    @Override
    public int getCount() {
        return mData==null?0:Integer.MAX_VALUE;
    }

    @Override
    public boolean isViewFromObject(View view, Object object) {
        return view==object;
    }

    @Override
    public Object instantiateItem(ViewGroup container, int position) {
        if(position%mData.size()==0){
            position=0;
        }else if(position%mData.size()==1){
            position=1;
        }
        if(mData.get(position).getParent()!=null){
            ViewPager viewPager = (ViewPager) mData.get(position).getParent();
            viewPager.removeView(mData.get(position));
        }

        container.addView(mData.get(position));
        return mData.get(position);
    }

    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {


    }
}
